//
//  JSONDispatcher.m
//  ATNetworks
//
//  Created by Ankit Thakur on 18/04/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ATJSONDispatcher.h"

#import "JSON.h"
@implementation ATJSONDispatcher

- (id) decodeJSONData:(NSData*)data_ withEncoding:(NSStringEncoding)encoding_
{
	NSString *responseResultString = [[NSString alloc] initWithData:data_ encoding:NSUTF8StringEncoding];
	
	
	SBJSON *jsonParser = [SBJSON new];
	
		// Parse the JSON into an Object
	
	id data = [jsonParser objectWithString:responseResultString error:NULL];
	
	
	[responseResultString release];
	
	
		//Release SBJSon Object
	[jsonParser dealloc];
	
	return data;
}

- (NSString*) encodeJSONData:(id)data_{
	
	SBJSON *jsonParser = [SBJSON new];
	jsonParser.humanReadable = YES;
	NSString *jsonString = [NSString stringWithFormat:@"%@", [data_ JSONFragment], nil];
	[jsonParser dealloc];
	
	return jsonString;
	
}

- (NSString*) encodeJSONData:(id)data_ withEncoding:(NSStringEncoding)encoding_{
	
	SBJSON *jsonParser = [SBJSON new];
	jsonParser.humanReadable = YES;
	NSString *jsonString = [NSString stringWithFormat:@"%@", [data_ JSONFragment], nil];
	[jsonParser dealloc];
	
	jsonString = [jsonString stringByAddingPercentEscapesUsingEncoding:encoding_];
	
	return jsonString;
	
}

@end
